package com.tjetc.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tjetc.domain.SpecializedGroup;
import com.tjetc.vo.Result;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.tjetc.mapper.DepartmentMapper;
import com.tjetc.domain.Department;
import com.tjetc.service.DepartmentService;

import java.util.List;

@Service
public class DepartmentServiceImpl implements DepartmentService{

    @Resource
    private DepartmentMapper departmentMapper;

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return departmentMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Department record) {
        return departmentMapper.insert(record);
    }

    @Override
    public int insertSelective(Department record) {
        return departmentMapper.insertSelective(record);
    }

    @Override
    public Department selectByPrimaryKey(Integer id) {
        return departmentMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Department record) {
        return departmentMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Department record) {
        return departmentMapper.updateByPrimaryKey(record);
    }

    @Override
    public Result selectAll() {
        List<Department> list=departmentMapper.selectAll();
        return Result.ok(list);
    }

    @Override
    public Result selAllDepartment() {
        return Result.ok(departmentMapper.selectAll());
    }

    @Override
    public PageInfo<Department> getByNameandPage(String name, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Department> list = departmentMapper.getByNameandPage(name);
        return new PageInfo<>(list);
    }

    @Override
    public Result save(Department department) {
        int i=0;
        if (department.getId() == null){
            i= departmentMapper.insertSelective(department);
        }else {
            i= departmentMapper.updateByPrimaryKeySelective(department);
        }
        return i==0?Result.fail("添加失败"):Result.ok();

    }

//    @Override
//    public Result selectAll() {
//        List<Department> list = departmentMapper.selectAll();
//        return Result.ok(list);
//    }

}
